package com.example.rocketmq.message;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 **/
@Component
public class Producerfilter {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer();
        producer.setNamesrvAddr("101.35.153.254:9876;121.5.23.139:9876;1.15.1.55:9876");
        producer.setProducerGroup("groupList");
        producer.start();
        List<Message> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Message message = new Message();
            message.setTopic("topicD");
            message.setTags("tagsA");
            message.setBody(("消息A"+i).getBytes());
            message.putUserProperty("num", String.valueOf(i));
            list.add(message);
        }

        SendResult sendResult = producer.send(list);
        System.out.println(sendResult);
        producer.shutdown();
    }
}
